﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;

namespace CMS6Tools.Common
{
    public class GenericNameTypeData<T> : NameTypeConfigurationElement, IInstancable<T>
    {
        public GenericNameTypeData()
            : base()
        {
        }

        public GenericNameTypeData(string name, Type type)
            : base(name, type)
        {
        }

        public virtual T CreateInstance()
        {
            if (Type != null && Type.IsClass && typeof(T).IsAssignableFrom(Type))
                return (T)Activator.CreateInstance(Type);
            return default(T);
        }
    }
}
